package day07_collections_map.com.itheima.d3_collection_test;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class Room {
    private ArrayList<Card> cards = new ArrayList<Card>();
    {
        String[] numbers = {"A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"};
        String[] colors = {"♠", "♥", "♣", "♦"};
        int size = 0;
        for (String number : numbers) {
            for (String color : colors) {
                Card c = new Card(number, color, size);
                cards.add(c);
            }
        }
        cards.add(new Card("", "🃏", ++size));
        cards.add(new Card("", "👲", ++size));
        System.out.println("cards = " + cards);
    }
    public void start(){
        Collections.shuffle( cards);
        System.out.println("cards = " + cards);

        ArrayList<Card> cards1 = new ArrayList<>();
        ArrayList<Card> cards2 = new ArrayList<>();
        ArrayList<Card> cards3 = new ArrayList<>();

        for (int i = 0; i < cards.size(); i++) {
            if(i % 3 == 0){
                cards1.add(cards.get(i));
            }else if(i % 3 == 1){
                cards2.add(cards.get(i));
            }else{
                cards3.add(cards.get(i));
            }
        }
        List<Card> lastThreeCards = cards.subList(cards.size() - 3, cards.size());
        cards1.addAll(lastThreeCards);

        sortCard(cards1);
        sortCard(cards2);
        sortCard(cards3);

        System.out.println("cards1 = " + cards1);
        System.out.println("cards2 = " + cards2);
        System.out.println("cards3 = " + cards3);
        System.out.println("lastThreeCards = " + lastThreeCards);
    }
    public void sortCard(List< Card> cards){
        Collections.sort(cards, new Comparator<Card>() {
            @Override
            public int compare(Card o1, Card o2) {
                return o2.getSize() - o1.getSize();
            }
        });

    }
}
